<?php
namespace app\manage\controller;

use app\manage\model\ApartmentValue;
use think\Controller;
use think\Validate;
use think\Db;
use Config;
use app\common\model\TokenCheck;

/**公寓设置
 * Class ApartmentSettings
 * @package app\manage\controller
 */
class ApartmentSettings extends Controller{
	/*public function __construct()
	{
		$this->token_check = new TokenCheck();
	}*/
    /**
     * 公寓设置显示
     * @return \think\response\Json
     */
	public function apartmentIndex(){
        $model=new \app\manage\model\ApartmentSettings();
        $data=$model->index();
       // if($data){
            returnJson(200,"成功",$data)->send();die;
       /* }else{
            returnJson(-401,"请求失败")->send();die;
        }*/
	}

    /**
     * 删除公寓设置的值
     * sv_id:设置id
     * @return \think\response\Json
     */
   public function apartmentDel(){
       $data = input();
       $sv_id = trim( $data['sv_id'] );
       $model=new ApartmentValue();
       $date=$model->del($sv_id);
       if( $date ){
           returnJson(200,"成功",$date)->send();die;
       }else{
           returnJson(-401,"请求失败",$date)->send();die;
       }
   }
    /**
     * 添加公寓设置的值
     * @return \think\response\Json
     */
    public function apartmentAdd(){
        $data = input();
        $model=new ApartmentValue();
        $validate = new Validate([
           /* ['inspection_time', 'require|number|between:1,15', '请填写抄表开始时间|抄表开始时间必须是数字|抄表开始时间设置只能1到15号'],
            ['end_inspection', 'require|number|between:1,15', '请填写抄表结束时间|抄表结束时间必须是数字|抄表结束时间设置只能1到15号'],
            ['settlement_time', 'require|number|between:1,15', '请填写结算时间|结算时间必须是数字|结算时间设置只能1到15号'],*/
            ['tung_num', 'require|number', '请填写栋数量|请填写栋数量必须是数字'],
            ['unit_num', 'require|number', '请填写单元楼数量|请填写单元楼数量'],
            /*['date_time', 'require|number|between:1,15', '请填写结算日后几天计算|结算日后几天计算必须是数字|结算日后几天计算设置只能1到15日']*/
        ]);
        if(!$validate->check($data))
        {
            returnJson(-1001,  $validate->getError())->send();die;
        }
        $date=$model->add($data);
        if( $date ){
            returnJson(200,"成功")->send();die;
        }else{
            returnJson(-401,"请求失败")->send();die;

        }
    }




}